package com.suzka.mapper;

import com.suzka.pojo.Customer;
import org.apache.ibatis.annotations.*;

import java.util.List;
/**
 * 客户数据访问映射接口
 * 使用MyBatis注解方式定义客户相关的数据库操作
 */
@Mapper
public interface CustomerMapper {
    @Select("SELECT * FROM customer")
    List<Customer> findAll();
    
    @Select("SELECT * FROM customer WHERE id = #{id}")
    Customer findById(Integer id);
    
    @Insert("INSERT INTO customer(name, gender, age, phone, address) VALUES(#{name}, #{gender}, #{age}, #{phone}, #{address})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Customer customer);
    
    @Update("UPDATE customer SET name=#{name}, gender=#{gender}, age=#{age}, phone=#{phone}, address=#{address} WHERE id=#{id}")
    int update(Customer customer);
    
    @Delete("DELETE FROM customer WHERE id = #{id}")
    int deleteById(Integer id);
    
    @Select("SELECT * FROM customer WHERE name LIKE CONCAT('%', #{keyword}, '%')")
    List<Customer> searchByName(String keyword);


}
